package com.siburian.MyStuff;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;

public class ListBab extends Activity implements View.OnClickListener {
	public int tempID = 1;
	int[] bintangTarget;
	int kelasAnak = 0;
	public int getSize;
	String[] arrData;
	Button[] profName;
	DBStudyType dbPelajaran;
	Bintang dataStar;
	EditText pertanyaan, kategori;
	TableLayout tabel4data;// tabel for data

	public static int idBab = 0;

	private static void getKelasSiswa(int bab) {
		ListBab.idBab = bab;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_bab);
		kelasAnak = ChooseKelas.kelasSiswa;
		dataStar = new Bintang(this);
		dbPelajaran = new DBStudyType(this);
		tabel4data = (TableLayout) findViewById(R.id.table_bab_kelas);

		viewData();
		Toast.makeText(getBaseContext(), " Jumlah data" + getSize,
				Toast.LENGTH_LONG).show();
	}

	protected void viewData() {
		while (tabel4data.getChildCount() > 1) {
			tabel4data.removeViewAt(1);
		}

		ArrayList<ArrayList<Object>> data = dbPelajaran.getProfile();//
		if (data.size() == 0) {
			dbPelajaran.generateData();
		}
		int k = 0;
		int kl = 0;
		k = ChooseKelas.kelasSiswa;
		kl = dbPelajaran.getBabUsingStudyType(k);
		bintangTarget = new int[kl];
		getSize = kl;
		for (int posisi = 0; posisi < kl; posisi++) {
			TableRow tabelBaris = new TableRow(this);
			TableRow tabelBaris2 = new TableRow(this);
			TableRow tabelBaris3 = new TableRow(this);
			bintangTarget[posisi] = tempID * 4;
			Button[] profName = new Button[kl];
			profName[posisi] = new Button(this);
			profName[posisi].setText(" Bab " + tempID);
			if (posisi > 0) {
				if (bintangTarget[posisi] > dataStar.getJumlah(
						ListProfil.profileID, posisi, kelasAnak,
						ListBelajar.typeStudy)) {
					profName[posisi].setEnabled(false);
				}
			}
			profName[posisi].setOnClickListener(this);
			profName[posisi].setId(tempID);
			tempID++;
			tabelBaris.addView(profName[posisi]);
			tabel4data.addView(tabelBaris);
		}
	}

	public void onClick(View v) {

		Button b = (Button) v;
		for (int i = 0; i < getSize; i++) {
			if (b.getId() == i) {
				idBab = i;
				if (ChooseMenu.MenuPilihan == "Belajar") {
					if (ListBelajar.typeStudy == 2) {
						if (ChooseKelas.kelasSiswa == 1) {
							Intent inte = new Intent(ListBab.this,
									LearnMatemathic.class);
							startActivity(inte);
						}

					} else {
						Intent inte = new Intent(ListBab.this,
								BelajarMembaca.class);
						startActivity(inte);
					}
				}
				if (ChooseMenu.MenuPilihan == "Test") {
					if (ListBelajar.typeStudy == 1) {
						Intent inte = new Intent(ListBab.this,
								TestActivityMembaca.class);
						startActivity(inte);
					}
					if (ListBelajar.typeStudy == 2) {
						if (ChooseKelas.kelasSiswa == 1) {
							Intent inte = new Intent(ListBab.this,
									PlayWithMatemathic.class);
							startActivity(inte);
						}
						if (ChooseKelas.kelasSiswa == 2) {
							Intent inte = new Intent(ListBab.this,
									PlayMathematic2.class);
							startActivity(inte);
						}
						if (ChooseKelas.kelasSiswa == 3) {
							Intent inte = new Intent(ListBab.this,
									PlayWithMathematic3.class);
							startActivity(inte);
						}
					}

				}
				if (ChooseMenu.MenuPilihan == "Statistik") {
					Intent inte = new Intent(ListBab.this, StatistikAnak.class);
					startActivity(inte);
				}
			}
		}
	}
}
